*Replication Do-File #2: Figure 3 and Table 2
*Sigman, Rachel, "Which Jobs for Which Boys? Party Finance and the Politics of State Job Distribution in Africa"
*Comparative Political Studies
*Conditional Acceptance: April 9, 2021

***THIS DO-FILE INCLUDES CODE TO RUN THE IRT MODEL THAT PRODUCES ESTIMATES OF POLITICIZATION THAT ARE USED THROUGHOUT SECTION 5.***

log using "WJWB_IRT_politicization_Log.smcl", replace

**************
***FIGURE 3***
**************

clear
clear matrix
clear mata
set maxvar 15000
use "Sigman_MinisterData_forIRT.dta", clear

***Summary Statistics for Biographical Variables (Table C.2 in Supplementary Material)***
bysort country: sum ed_gen ed_spec prof_gen prof_spec exp_match2 partymember pol_exp cadre mpbefore

***Cronbach's Alpha (Table C.3 in Supplementary Material)***
alpha ed_gen ed_spec prof_gen prof_spec exp_match2 partymember pol_exp cadre mpbefore, item

***Bayesian IRT to estimate Politicization score (NOTE: Takes several hours to run)***
keep appt_id country_id presterm ed_gen ed_spec prof_gen prof_spec exp_match2 mpbefore partymember cadre pol_exp
rename ed_gen q1
rename ed_spec q2
rename prof_gen q3
rename prof_spec q4
rename exp_match2 q5
rename partymember q6
rename pol_exp q7
rename mpbefore q8
rename cadre q9

quietly reshape long q, i(appt_id) j(item)

rename q y
fvset base none appt_id item

set seed 321
bayesmh y = ({discrim:}*({subj:}-{diff:})), likelihood(logit) ///
         redefine(discrim:i.item) redefine(diff:i.item)        ///
         redefine(subj:i.appt_id)                                   ///
         prior({subj:i.appt_id},     normal(0, 1))   nchains(3)           ///
         prior({discrim:i.item}, lognormal({mu_a}, {var_a}))   ///
         prior({diff:i.item},    normal({mu_b}, {var_b}))      ///
         prior({mu_a} {mu_b},    normal(0, 0.1))              ///
         prior({var_a} {var_b},  igamma(10, 1))                ///
         block({mu_a mu_b var_a var_b}, split)                 ///
		 init({discrim:i.item} 1)							   ///
         burnin(5000) mcmcs(50000) saving(sim2pl, replace)

***Retrieve mean posterior distributions for each appt_id, difficulty, and discrimination parameters:		 
bayesstats summary, hpd

*NOTE: THE ESTIMATES OF POLITICIZATION FOR EACH MINISTER APPOINTMENT ARE THE MEANS LISTED UNDER "subj" IN THE STATA OUTPUT. YOU MUST COPY THESE ESTIMATES AND PASTE THEM INTO A SEPARATE FILE IN ORDER TO MAKE THEM USABLE. I HAVE SAVED AND MERGED THEM INTO THE FILE "Sigman_MinisterDataFull_replication.dta"

**NOTE: DUE TO THE MCMC MODEL SET-UP, THE ESTIMATES FROM EACH MODEL WILL BE SLIGHTLY DIFFERENT THAN PREVIOUS RUNS.

log close



